<template>
  <q-page class="cc-admin">
    <div>
      <div class="row">
        <q-item class="col-md-3 col-sm-6 col-xs-12 items-center">
          <q-item-label>公司名称：</q-item-label>
          <q-item-section class="col row">
            <q-input outlined dense v-model="searchForm.name" />
          </q-item-section>
        </q-item>
        <q-item class="col-md-3 col-sm-6 col-xs-12 items-center">
          <q-item-label>管理员账号：</q-item-label>
          <q-item-section class="col row">
            <q-input outlined dense v-model="searchForm.userId" />
          </q-item-section>
        </q-item>
        <q-item class="col-md-3 col-sm-6 col-xs-12 items-center">
          <q-item-section>
            <div class="row justify-center">
              <q-btn unelevated no-wrap label="查询" color="primary" class="q-mx-xs" icon="search" :loading="loading" @click="query()">
                <template v-slot:loading>
                  <q-spinner-ios class="on-center" />
                </template>
              </q-btn>
              <q-btn outline no-wrap unelevated label="重置" class="q-mx-xs" color="primary" icon="refresh" @click="searchReset" />
            </div>
          </q-item-section>
        </q-item>
      </div>
      <q-table flat color="primary" class="cross_table" separator="cell" :columns="columns" :data="list" row-key="id" :pagination.sync="pagination" :visible-columns="group" @request="query" :rows-per-page-options="[10, 20, 50, 100]" :selection="mobile ? 'none' : 'multiple'" :selected.sync="selected">
        <template v-slot:top="table">
          <div class="row no-wrap full-width">
            <q-space />
            <table-top-btns :table="table" :selected="selected" :importing="importing" :exporting="exporting" :importExcelUrlFull="importExcelUrlFull" :columns="columns" @groupChange="groupChange" @add="add" @importExcel="importExcel" @exportExcel="exportExcel" @showConfirm="showConfirm" />
          </div>
        </template>
        <template #body-cell-signType="props">
          <q-td key="signType" :props="props">{{ getDictLabel(signTypeOptions, props.row.signType) }}</q-td>
        </template>
        <template #body-cell-opt="props">
          <q-td :props="props" :auto-width="true">
            <cc-btn label="编辑" color="primary" icon="edit" @click="edit(props.row)"> <q-tooltip>编辑</q-tooltip></cc-btn>
          </q-td>
        </template>
      </q-table>
    </div>
    <cc-dialog ref="dialog" :title="`${editType}公司管理`" @submit="submit">
      <div class="col-6">
        <h5>
          <q-icon name="star" color="red" />公司编号：
        </h5>
        <q-input outlined dense v-model="form.id" hide-bottom-space type="text" :rules="[requiredTest]" maxlength="3" :readonly="editType === '编辑'" @input="idInput" />
      </div>
      <div class="col-6">
        <h5>
          <q-icon name="star" color="red" />公司名称：
        </h5>
        <q-input outlined dense hide-bottom-space v-model="form.name" type="text" :rules="[requiredTest]" />
      </div>
      <div class="col-6">
        <h5>
          <q-icon name="star" color="red" />管理员账号：
        </h5>
        <q-input outlined dense hide-bottom-space v-model="form.contactTelephone" readonly type="text" :rules="[requiredTest]" />
      </div>
      <div class="col-6">
        <h5>
          <q-icon name="star" color="red" />管理员姓名：
        </h5>
        <q-input outlined dense hide-bottom-space v-model="form.contact" readonly type="text" :rules="[requiredTest]" />
      </div>
      <div class="col-6">
        <h5><q-icon name="star" color="red" /> 许可生效时间：</h5>
        <input-date-picker dense debounce="500" hide-bottom-space outlined v-model="form.forceDate" type="date" :form="form" lazy-rules :rules="[requiredTest]" />
      </div>
      <div class="col-6">
        <h5><q-icon name="star" color="red" /> 许可失效时间：</h5>
        <input-date-picker dense debounce="500" hide-bottom-space outlined v-model="form.deadDate" type="date" :form="form" lazy-rules :rules="[requiredTest]" />
      </div>
      <div class="col-6">
        <h5>
          logo地址：
        </h5>
        <q-input outlined dense v-model="form.logo" type="text" />
      </div>
      <div class="col-6">
        <h5>
          密码最少字符：
        </h5>
        <q-input outlined dense v-model="form.minLength" type="text" />
      </div>
      <div class="col-6">
        <h5>
          密码最大字符：
        </h5>
        <q-input outlined dense v-model="form.maxLength" type="text" />
      </div>
      <div class="col-6">
        <h5>
          密码规则：
        </h5>
        <q-input outlined dense v-model="form.pswStrength" type="text" />
      </div>
      <div class="col-6">
        <h5>
          密码规则提示信息：
        </h5>
        <q-input outlined dense v-model="form.pswMsg" type="text" />
      </div>
      <div class="col-6">
        <h5>
          修改密码间隔（天 0代表不需要修改）：
        </h5>
        <q-input outlined dense v-model="form.updateDay" type="number" />
      </div>
      <div class="col-6">
        <h5>
          签字类型：
        </h5>
        <q-select outlined dense emit-value v-model="form.signType" map-options :options="signTypeOptions" :rules="[requiredTest]" />
      </div>
      <div class="col-6">
        <h5>
          通知时间：
        </h5>
        <input-date-picker dense debounce="500" hide-bottom-space outlined v-model="form.sendTime" type="time" :form="form" />
      </div>
    </cc-dialog>
    <confirm ref="confirmDialog" :msg="confirmMsg" @confirm="deleteBatch()" />
    <cc-loading :loading="loading" />
  </q-page>
</template>

<script>
import { date } from 'quasar';
import { IndexMixin } from 'boot/mixins';
import { getDictLabel } from 'boot/dictionary';
import confirm from 'components/confirm';
import { requiredTest } from 'boot/inputTest';

export default {
  name: 'SysCompany',
  mixins: [IndexMixin],
  components: {
    confirm,
  },
  data() {
    return {
      columns: [
        {
          name: 'index',
          align: 'center',
          label: '序号',
          field: 'index',
          headerClasses: 'cc-table-index',
        },
        {
          name: 'id', align: 'center', label: '公司编号', field: 'id',
        },
        {
          name: 'name', align: 'center', label: '公司名称', field: 'name',
        },
        {
          name: 'forceDate', align: 'left', label: '许可生效时间', field: 'forceDate',
        },
        {
          name: 'deadDate', align: 'left', label: '许可失效时间', field: 'deadDate',
        },
        {
          name: 'signType', align: 'left', label: '签字类型', field: 'signType',
        },
        {
          name: 'opt', align: 'center', label: '操作', field: 'opt',
        },
      ],
      sysDepart: [],
      showQuery: true,
      headers: [{ name: 'Authorization', value: localStorage.Authorization }],
      uploadUrl: `${process.env.BASE_URL}/sys/common/upload`,
      imgUrl: `${process.env.BASE_URL}/sys/common/static`,
      url: {
        list: '/sys/company/list',
        add: '/sys/company/add',
        edit: '/sys/company/edit',
        copy:
          '/sys/company/copy',
        delete: '/sys/company/delete',
        deleteBatch: '/sys/company/deleteBatch',
        exportXlsUrl: '/sys/company/exportXls',
        importExcelUrl: '/sys/company/importExcel',
      },
      signTypeOptions: [{ value: 'psw', label: '密码签字' }, { value: 'hand', label: '手写签字' }, { value: 'mouse', label: '鼠标签字' }],
    };
  },
  methods: {
    requiredTest,
    getDictLabel,
    initDict() {

    },
    idInput(v) {
      this.form.contactTelephone = `sysadmin${v}`;
      this.form.contact = `系统管理员${v}`;
    },
    add() {
      this.editType = '新建';
      const timeStamp = Date.now();
      const forceDate = date.formatDate(timeStamp, 'YYYY-MM-DD');
      const { addToDate } = date;
      const endDate = addToDate(new Date(), { year: 1 });
      const deadDate = date.formatDate(endDate, 'YYYY-MM-DD');
      this.form = {
        id: 'a02',
        name: '测试公司a02',
        contactTelephone: 'sysadmina02',
        contact: '系统管理员a02',
        forceDate,
        deadDate,
        updateDay: 0
      };
      this.$refs.dialog.show();
    },
  },
  mounted() {
    this.initDict();
  },
};
</script>

<style lang="stylus"></style>
